'use strict';

const sudo = require('sudo-prompt');
const path = require('path');

const NOTEPAD_PATH = path.join(process.env.windir || process.env.SystemRoot, 'System32', 'notepad.exe');

const UNINSTALL_REG = [
    'cmd /c chcp 437 & reg add "HKCR\\VBXFile\\shell\\edit\\command" /ve /d "\\"' + NOTEPAD_PATH + '\\" \\"%%1\\"" /f', 
    'cmd /c chcp 437 & reg add "HKCR\\CSXFile\\shell\\edit\\command" /ve /d "\\"' + NOTEPAD_PATH + '\\" \\"%%1\\"" /f',
];

function runCmd(commands) {
    for (let cmd of commands) {
        console.log(cmd);
        sudo.exec(cmd, (error, stdout, stderr) => {
            if (error) {
                console.log(`Error: ${error.message}`);
            }
        });
    }
}

if (process.platform === "win32") {
    runCmd(UNINSTALL_REG);
} 
